#include"User.hpp"

int main() {
    try {
        // 创建Mapper实例
        UserMapper mapper("tcp://112.74.40.147:3306", "root", "Ahqjhqj73@you", "novel_db");
        
        // === 用户操作示例 ===
        
        // 创建新用户
        User newUser;
        newUser.name = "张三";
        newUser.email = "zhangsan@example.com";
        newUser.password = "hashed_password";
        newUser.phone = "13800138000";
        newUser.age = 30;
        
        int userId = mapper.createUser(newUser);
        std::cout << "新用户ID: " << userId << std::endl;
        
        // 查询用户
        auto user = mapper.getUserById(userId);
        if (user) {
            std::cout << "用户姓名: " << user->name << std::endl;
        }
        
        // 更新用户信息
        if (user) {
            user->name = "张老三";
            mapper.updateUser(*user);
        }
        
        // === 评论操作示例 ===
        
        // 添加评论
        UserComment comment;
        comment.user_id = userId;
        comment.content = "这本书非常精彩！";
        int commentId = mapper.addUserComment(comment);
        std::cout << "评论ID: " << commentId << std::endl;
        
        // 获取用户所有评论
        auto comments = mapper.getUserComments(userId);
        std::cout << "评论数量: " << comments.size() << std::endl;
        
        // === 借阅操作示例 ===
        
        // 添加借阅记录
        UserBorrowRecord borrow;
        borrow.user_id = userId;
        borrow.book_id = 1001;
        borrow.borrow_date = time(nullptr); // 当前时间
        int borrowId = mapper.addBorrowRecord(borrow);
        std::cout << "借阅ID: " << borrowId << std::endl;
        
        // 归还书籍
        mapper.returnBook(borrowId, time(nullptr));
        
        // 获取用户所有借阅记录
        auto borrows = mapper.getUserBorrowRecords(userId);
        std::cout << "借阅记录数量: " << borrows.size() << std::endl;
        
    } catch (const std::exception& e) {
        std::cerr << "错误: " << e.what() << std::endl;
    }
    
    return 0;
}